﻿using System;
using System.Collections.Generic;
using System.Text;
using XDesigner.ORM ;

namespace XDesigner.AppFramework.DOM
{
    [Serializable()]
    public class AppDocument
    {
        public AppDocument()
        {
            _Config.ID = 0;
            _Config.Name = "Application config";
        }

        [NonSerialized()]
        internal AppFrameworkClass _Engine = null;

        public AppFrameworkClass Engine
        {
            get { return _Engine; }
        }
         

        private AppConfig _Config = new AppConfig();

        public AppConfig Config
        {
            get { return _Config; }
            set { _Config = value; }
        }

        private List<AppUser> _Users = null ;

        public List<AppUser> Users
        {
            get
            {
                if (_Users == null && this.Engine.ORMEngine != null )
                {
                    Array users = this.Engine.ORMEngine.ReadAllInstances(typeof(AppUser));
                    if (users != null)
                    {
                        _Users = new List<AppUser>();
                        foreach (AppUser usr in users)
                        {
                            _Users.Add(usr);
                        }
                    }
                }
                return _Users; 
            }
            set
            {
                _Users = value; 
            }
        }

        private List<AppRole> _Roles = null;

        public List<AppRole> Roles
        {
            get { return _Roles; }
            set { _Roles = value; }
        }

        private List<AppPermission> _Permissions = null;

        public List<AppPermission> Permissions
        {
            get { return _Permissions; }
            set { _Permissions = value; }
        }
    }
}
